import {
  ENUM_MessageCodeTemplate,
  getMessageCode,
} from "@monorepo/shared/validators/core";
import assert from "assert";
import type { Request } from "express";
import jwt from "jsonwebtoken";

/** 签权验证 */
export const authVerification = async (req: Request): Promise<boolean> => {
  // 从请求头中获取 token
  const token = req.headers.authorization?.split(" ").pop() || undefined;

  // token是否为空
  assert.ok(
    token,
    getMessageCode(ENUM_MessageCodeTemplate.NOT_EXISTS, "token")
  );

  // TODO 实现你自己的 token 验证方法
  // ....

  // 默认签权正确
  return true;
};
